﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;

using System.ServiceModel.DomainServices.Client;

namespace LEEAAttendanceControl.Views
{
    public partial class SpecificExceptionsAssignments : Page
    {
        public SpecificExceptionsAssignments()
        {
            InitializeComponent();

            Title = ((App)Application.Current).DisplayName + ": Exception Assignments";

            LoadEmployeeExceptionsAssignments();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            App myApp = (App)Application.Current;

            myApp.ClearEvents();

            ExAssignmentsBlock.Text = myApp.DisplayName + ": Exception Assignments";

            myApp.ChangeEmployeesEvent += ReloadExceptionsAssignmentsHandler;
        }

        private void ExceptionsDaysDataSource_LoadingData(object sender, LoadingDataEventArgs e)
        {
            e.LoadBehavior = LoadBehavior.RefreshCurrent;
        }

        private void LoadEmployeeExceptionsAssignments()
        {
            ExceptionsDaysDataSource.QueryParameters.Clear();

            Parameter empParameter = new Parameter();

            empParameter.ParameterName = "id";
            empParameter.Value = ((App)Application.Current).EmployeeId;

            ExceptionsDaysDataSource.QueryParameters.Add(empParameter);

            Parameter fromParameter = new Parameter();

            fromParameter.ParameterName = "from";
            fromParameter.Value = ((App)Application.Current).PeriodFrom.Date;

            ExceptionsDaysDataSource.QueryParameters.Add(fromParameter);

            Parameter toParameter = new Parameter();

            toParameter.ParameterName = "to";
            toParameter.Value = ((App)Application.Current).PeriodTo.Date;

            ExceptionsDaysDataSource.QueryParameters.Add(toParameter);

            ExceptionsDaysDataSource.Load();
        }

        public void ReloadExceptionsAssignmentsHandler(object sender, EventArgs e)
        {
            LoadEmployeeExceptionsAssignments();
        }
    }
}
